package demo1;

import java.util.LinkedList;
import java.util.ListIterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-09-06
 * Time: 13:15
 */
public class Test01 {
    public static void main(String[] args) {
        LinkedList<Integer> list1 = new LinkedList<>();
        list1.add(11);
        list1.add(22);
        list1.add(33);
        //方法1：
        System.out.println(list1);
        //方法2:
        for (int i = 0; i < list1.size(); i++) {
            System.out.print(list1.get(i) + " ");
        }
        System.out.println();
        //方法3：
        for(int i : list1) {
            System.out.print(i + " ");
        }
        System.out.println();
        //方法4(迭代器)正向遍历：
        ListIterator<Integer> it = list1.listIterator();
        while(it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();
        //迭代器反向遍历:
        ListIterator<Integer> itN = list1.listIterator(list1.size());
        while(itN.hasPrevious()) {
            System.out.print(itN.previous() + " ");
        }
    }
    public static void main2(String[] args) {
        LinkedList<Integer> list1 = new LinkedList<>();
        list1.add(11);
        list1.add(22);
        list1.add(33);
        LinkedList<Integer> list2 = new LinkedList<>(list1);
        System.out.println(list2);
    }
    public static void main1(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
//        myLinkedList.addFirst(11);
//        myLinkedList.addFirst(12);
//        myLinkedList.addFirst(13);
//        myLinkedList.addFirst(14);
//        myLinkedList.display();
        myLinkedList.addLast(11);
        myLinkedList.addLast(11);
        myLinkedList.addLast(11);
        myLinkedList.addLast(11);
        myLinkedList.display();
//        myLinkedList.addIndex(2,1);
//        myLinkedList.display();
//        System.out.println(myLinkedList.contains(12));
//        myLinkedList.removeAllKey(11);
        System.out.println("=========");
        myLinkedList.clear();
        myLinkedList.display();

    }
}
